/**
 * Copyrigth 2007 Aurelien Moreau
 * 
 * This file is part of ProcessShop.
 * 
 * ProcessShop is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * ProcessShop is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with ProcessShop; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * $Id$
 */
package net.yienyien.process.bpd.provider;

import java.util.ArrayList;
import java.util.Collection;

import net.yienyien.process.bpd.util.BpdAdapterFactory;

import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.Notifier;

import org.eclipse.emf.edit.provider.ChangeNotifier;
import org.eclipse.emf.edit.provider.ComposeableAdapterFactory;
import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
import org.eclipse.emf.edit.provider.IChangeNotifier;
import org.eclipse.emf.edit.provider.IDisposable;
import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
import org.eclipse.emf.edit.provider.IItemLabelProvider;
import org.eclipse.emf.edit.provider.IItemPropertySource;
import org.eclipse.emf.edit.provider.INotifyChangedListener;
import org.eclipse.emf.edit.provider.IStructuredItemContentProvider;
import org.eclipse.emf.edit.provider.ITreeItemContentProvider;

/**
 * This is the factory that is used to provide the interfaces needed to support Viewers.
 * The adapters generated by this factory convert EMF adapter notifications into calls to {@link #fireNotifyChanged fireNotifyChanged}.
 * The adapters also support Eclipse property sheets.
 * Note that most of the adapters are shared among multiple instances.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public class BpdItemProviderAdapterFactory extends BpdAdapterFactory implements ComposeableAdapterFactory, IChangeNotifier, IDisposable {
	/**
	 * This keeps track of the root adapter factory that delegates to this adapter factory.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected ComposedAdapterFactory parentAdapterFactory;

	/**
	 * This is used to implement {@link org.eclipse.emf.edit.provider.IChangeNotifier}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected IChangeNotifier changeNotifier = new ChangeNotifier();

	/**
	 * This keeps track of all the supported types checked by {@link #isFactoryForType isFactoryForType}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected Collection<Object> supportedTypes = new ArrayList<Object>();

	/**
	 * This constructs an instance.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public BpdItemProviderAdapterFactory() {
		supportedTypes.add(IEditingDomainItemProvider.class);
		supportedTypes.add(IStructuredItemContentProvider.class);
		supportedTypes.add(ITreeItemContentProvider.class);
		supportedTypes.add(IItemLabelProvider.class);
		supportedTypes.add(IItemPropertySource.class);
	}

	/**
	 * This keeps track of the one adapter used for all {@link net.yienyien.process.bpd.Task} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected TaskItemProvider taskItemProvider;

	/**
	 * This creates an adapter for a {@link net.yienyien.process.bpd.Task}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createTaskAdapter() {
		if (taskItemProvider == null) {
			taskItemProvider = new TaskItemProvider(this);
		}

		return taskItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link net.yienyien.process.bpd.StartEvent} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected StartEventItemProvider startEventItemProvider;

	/**
	 * This creates an adapter for a {@link net.yienyien.process.bpd.StartEvent}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createStartEventAdapter() {
		if (startEventItemProvider == null) {
			startEventItemProvider = new StartEventItemProvider(this);
		}

		return startEventItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link net.yienyien.process.bpd.IntermediateEvent} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected IntermediateEventItemProvider intermediateEventItemProvider;

	/**
	 * This creates an adapter for a {@link net.yienyien.process.bpd.IntermediateEvent}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createIntermediateEventAdapter() {
		if (intermediateEventItemProvider == null) {
			intermediateEventItemProvider = new IntermediateEventItemProvider(this);
		}

		return intermediateEventItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link net.yienyien.process.bpd.EndEvent} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected EndEventItemProvider endEventItemProvider;

	/**
	 * This creates an adapter for a {@link net.yienyien.process.bpd.EndEvent}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createEndEventAdapter() {
		if (endEventItemProvider == null) {
			endEventItemProvider = new EndEventItemProvider(this);
		}

		return endEventItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link net.yienyien.process.bpd.ParallelFork} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected ParallelForkItemProvider parallelForkItemProvider;

	/**
	 * This creates an adapter for a {@link net.yienyien.process.bpd.ParallelFork}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createParallelForkAdapter() {
		if (parallelForkItemProvider == null) {
			parallelForkItemProvider = new ParallelForkItemProvider(this);
		}

		return parallelForkItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link net.yienyien.process.bpd.ParallelJoin} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected ParallelJoinItemProvider parallelJoinItemProvider;

	/**
	 * This creates an adapter for a {@link net.yienyien.process.bpd.ParallelJoin}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createParallelJoinAdapter() {
		if (parallelJoinItemProvider == null) {
			parallelJoinItemProvider = new ParallelJoinItemProvider(this);
		}

		return parallelJoinItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link net.yienyien.process.bpd.DataBasedXOR} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected DataBasedXORItemProvider dataBasedXORItemProvider;

	/**
	 * This creates an adapter for a {@link net.yienyien.process.bpd.DataBasedXOR}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createDataBasedXORAdapter() {
		if (dataBasedXORItemProvider == null) {
			dataBasedXORItemProvider = new DataBasedXORItemProvider(this);
		}

		return dataBasedXORItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link net.yienyien.process.bpd.EventBasedXOR} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected EventBasedXORItemProvider eventBasedXORItemProvider;

	/**
	 * This creates an adapter for a {@link net.yienyien.process.bpd.EventBasedXOR}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createEventBasedXORAdapter() {
		if (eventBasedXORItemProvider == null) {
			eventBasedXORItemProvider = new EventBasedXORItemProvider(this);
		}

		return eventBasedXORItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link net.yienyien.process.bpd.XORMerge} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected XORMergeItemProvider xorMergeItemProvider;

	/**
	 * This creates an adapter for a {@link net.yienyien.process.bpd.XORMerge}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createXORMergeAdapter() {
		if (xorMergeItemProvider == null) {
			xorMergeItemProvider = new XORMergeItemProvider(this);
		}

		return xorMergeItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link net.yienyien.process.bpd.ControlFlowRelation} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected ControlFlowRelationItemProvider controlFlowRelationItemProvider;

	/**
	 * This creates an adapter for a {@link net.yienyien.process.bpd.ControlFlowRelation}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createControlFlowRelationAdapter() {
		if (controlFlowRelationItemProvider == null) {
			controlFlowRelationItemProvider = new ControlFlowRelationItemProvider(this);
		}

		return controlFlowRelationItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link net.yienyien.process.bpd.BPDModel} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected BPDModelItemProvider bpdModelItemProvider;

	/**
	 * This creates an adapter for a {@link net.yienyien.process.bpd.BPDModel}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createBPDModelAdapter() {
		if (bpdModelItemProvider == null) {
			bpdModelItemProvider = new BPDModelItemProvider(this);
		}

		return bpdModelItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link net.yienyien.process.bpd.BPDComponent} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected BPDComponentItemProvider bpdComponentItemProvider;

	/**
	 * This creates an adapter for a {@link net.yienyien.process.bpd.BPDComponent}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createBPDComponentAdapter() {
		if (bpdComponentItemProvider == null) {
			bpdComponentItemProvider = new BPDComponentItemProvider(this);
		}

		return bpdComponentItemProvider;
	}

	/**
	 * This returns the root adapter factory that contains this factory.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public ComposeableAdapterFactory getRootAdapterFactory() {
		return parentAdapterFactory == null ? this : parentAdapterFactory.getRootAdapterFactory();
	}

	/**
	 * This sets the composed adapter factory that contains this factory.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setParentAdapterFactory(ComposedAdapterFactory parentAdapterFactory) {
		this.parentAdapterFactory = parentAdapterFactory;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean isFactoryForType(Object type) {
		return supportedTypes.contains(type) || super.isFactoryForType(type);
	}

	/**
	 * This implementation substitutes the factory itself as the key for the adapter.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter adapt(Notifier notifier, Object type) {
		return super.adapt(notifier, this);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object adapt(Object object, Object type) {
		if (isFactoryForType(type)) {
			Object adapter = super.adapt(object, type);
			if (!(type instanceof Class) || (((Class<?>)type).isInstance(adapter))) {
				return adapter;
			}
		}

		return null;
	}

	/**
	 * This adds a listener.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void addListener(INotifyChangedListener notifyChangedListener) {
		changeNotifier.addListener(notifyChangedListener);
	}

	/**
	 * This removes a listener.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void removeListener(INotifyChangedListener notifyChangedListener) {
		changeNotifier.removeListener(notifyChangedListener);
	}

	/**
	 * This delegates to {@link #changeNotifier} and to {@link #parentAdapterFactory}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void fireNotifyChanged(Notification notification) {
		changeNotifier.fireNotifyChanged(notification);

		if (parentAdapterFactory != null) {
			parentAdapterFactory.fireNotifyChanged(notification);
		}
	}

	/**
	 * This disposes all of the item providers created by this factory. 
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void dispose() {
		if (taskItemProvider != null) taskItemProvider.dispose();
		if (startEventItemProvider != null) startEventItemProvider.dispose();
		if (intermediateEventItemProvider != null) intermediateEventItemProvider.dispose();
		if (endEventItemProvider != null) endEventItemProvider.dispose();
		if (parallelForkItemProvider != null) parallelForkItemProvider.dispose();
		if (parallelJoinItemProvider != null) parallelJoinItemProvider.dispose();
		if (dataBasedXORItemProvider != null) dataBasedXORItemProvider.dispose();
		if (eventBasedXORItemProvider != null) eventBasedXORItemProvider.dispose();
		if (xorMergeItemProvider != null) xorMergeItemProvider.dispose();
		if (controlFlowRelationItemProvider != null) controlFlowRelationItemProvider.dispose();
		if (bpdModelItemProvider != null) bpdModelItemProvider.dispose();
		if (bpdComponentItemProvider != null) bpdComponentItemProvider.dispose();
	}

}
